package com.ruoyi.wmsorder.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wmsorder.domain.WmsPurchaseorder;
import com.ruoyi.wmsorder.domain.WmsSaleorder;
import com.ruoyi.wmsorder.domain.vo.WmsPurchaseorderPoPVO;
import com.ruoyi.wmsorder.domain.vo.WmsSaleorderPoPVO;
import com.ruoyi.wmsorder.domain.vo.WmsSaleorderVO;
import com.ruoyi.wmsorder.service.IWmsSaleorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 销售订单Controller
 * 
 * @author ruoyi
 * @date 2024-03-12
 */
@RestController
@RequestMapping("/order/saleorder")
public class WmSaleOrderController extends BaseController
{
    @Autowired
    private IWmsSaleorderService wmsSaleorderService;
    /**
     * 查询销售订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:saleorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsSaleorder wmsSaleorder)
    {
        startPage();
        PageDomain pageDomain = new PageDomain();
    pageDomain.setOrderByColumn("create_time");
    pageDomain.setIsAsc("desc");
        List<WmsSaleorderVO> wmsSaleorders = wmsSaleorderService.selectWmsSaleorderList(wmsSaleorder);
        return getDataTable(wmsSaleorders);
    }
 /**
     * 查询销售订单弹窗列表
     */
    @PreAuthorize("@ss.hasPermi('order:saleorder:popList')")
    @GetMapping("/popList")
    public TableDataInfo popList(WmsSaleorder wmsSaleorder)
    {
        startPage();

        List<WmsSaleorderPoPVO> list = wmsSaleorderService.selectWmsSaleorderPopList(wmsSaleorder);
        return getDataTable(list);
    }

    /**
     * 导出销售订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:saleorder:export')")
    @Log(title = "销售订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsSaleorder wmsSaleorder)
    {
//
    }

    /**
     * 获取销售订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:saleorder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {

        System.out.println("ididiidiidii = " + id);
        return success(wmsSaleorderService.selectWmsSaleorderById(id));
    }

    /**
     * 新增销售订单
     */
    @PreAuthorize("@ss.hasPermi('order:saleorder:add')")
    @Log(title = "销售订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsSaleorder wmsSaleorder)

    {

        wmsSaleorder.setCreateById(getUserId());
        wmsSaleorder.setUpdateById(getUserId());
        return toAjax(wmsSaleorderService.insertWmsSaleorder(wmsSaleorder));
    }

    /**
     * 修改销售订单
     */
    @PreAuthorize("@ss.hasPermi('order:saleorder:edit')")
    @Log(title = "销售订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsSaleorder wmsSaleorder)
    {

        wmsSaleorder.setUpdateById(getUserId());
        return toAjax(wmsSaleorderService.updateWmsSaleorder(wmsSaleorder));
    }

    /**
     * 删除销售订单
     */
    @PreAuthorize("@ss.hasPermi('order:saleorder:remove')")
    @Log(title = "销售订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wmsSaleorderService.deleteWmsSaleorderByIds(ids));
    }
}
